home *** CD-ROM | disk | FTP | other *** search
- /*
- File: FWXDrag.c
-
- Contains: Software to handle Finder drag copies onto FireWire File Exchange icons.
-
- Version: 1.0
-
- Written by: Jay Lloyd
-
- Copyright: © 1996-1999 by Apple Computer, Inc., all rights reserved.
-
- File Ownership:
-
- DRI: Jay Lloyd
-
- Other Contact:
-
- Technology: FireWire
-
- Writers:
-
- (DCB) Clinton Bauder
- (jkl) Jay Lloyd
-
- Change History (most recent first):
-
- <FW18> 4/8/99 jkl More interface cleanup.
- <FW17> 12/19/98 DCB More cleanup for SDK.
- <FW16> 2/1/98 jkl Include Errors.h.
- <FW15> 1/15/98 jkl Update for new headers.
- <FW14> 6/19/97 jkl Made SendFSSpecListToSelf available globally for send
- AppleScript command.
- <FW13> 5/16/97 jkl Disposed of region handle in HandleDragTracking.
- <FW12> 5/7/97 jkl Updated data structure field names.
- <FW11> 4/29/97 jkl Made sure node drag hiliting is clipped within the scroll bars
- and window.
- <FW10> 3/18/97 jkl Changed drag hiliting to hilite node icon and name.
- <FW9> 2/27/97 jkl Updated drag receive routine to handle window scrolling.
- <FW8> 2/19/97 jkl Fixed a problem with GetNodeInfo returning bad error message.
- <FW7> 2/2/97 jkl Corrected the DragReceive routine to only recognize a drop in a
- node rectangle.
- <FW6> 1/27/97 jkl Changed the HandleFSItems routine to call a routine to add the
- items to a send check queue, instead of calling a preflight
- check and attempting send..
- <FW5> 1/16/97 jkl Added user interface features for alpha candidate. Changed
- window handling to normal window behavior and updated drag
- tracking for this.
- <FW4> 1/8/97 ES Changed to use FWX nodes instead of FWX drivers.
- <FW3> 11/13/96 jkl Added accessor routines to get receive node name and node info
- record.
- <FW2> 10/31/96 jkl Added code to start check for receiver node
- being able to handle copy. Added support for
- multiple file/folder drops. Changed drag
- acceptance to not accept drag if copy in progress.
- <FW1> 10/2/96 jkl initial check-in, based on DTS FinderDrag
- */
-
- #include <Types.h>
- #include <Errors.h>
- #include <QuickDraw.h>
- #include <Files.h>
- #include <Controls.h>
- #include <AppleEvents.h>
- #include <Processes.h>
- #include <Drag.h>
- #include <Windows.h>
- #include <Devices.h>
- #include <Timer.h>
- #include <Icons.h>
-
- #include "FWiX.h"
- #include "FWiXmain.h"
- #include "FWiXdrag.h"
-
- #include <stdio.h>
- extern char debugStr[256];
- static pascal void FWDebugStr(
- ConstStr255Param debuggerMsg)
- {
- #ifdef FW_DEBUG_BUILD
- #if FW_DEBUG_BUILD
- DebugStr (debuggerMsg);
- #endif
- #endif
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // Internal procedure prototypes.
- //
-
- OSErr InstallDragHandlers (void);
-
- void RemoveDragHandlers (void);
-
- static Boolean MouseIsInContentRgn (
- DragReference theDrag,
- WindowPtr pWin);
-
- static Boolean DragItemsAreAcceptable (
- DragReference theDrag);
-
- static pascal OSErr HandleDragTracking (
- DragTrackingMessage theMessage,
- WindowPtr pWin,
- void *handlerRefCon,
- DragReference theDrag);
-
- static pascal OSErr HandleDragReceive (
- WindowPtr pWin,
- void *handlerRefCon,
- DragReference theDrag);
-
- OSErr GetNodeInfo (
- FWXNodeID nodeID,
- RecvNodePtr *pRecvNode);
-
- OSErr GetNodeDragRect (
- WindowPtr pWin,
- SInt16 spaceIndex,
- Rect *iconRect,
- Rect *textRect);
-
- OSErr GetNodeName (
- WindowPtr pWin,
- SInt16 spaceIndex,
- StringPtr *pString);
-
- static SInt16 WhichRecvNode (
- WindowPtr pWin,
- Point localPt);
-
- static void GetNodeIDFromIndex(
- SInt16 nodeIndex,
- FWXNodeID *whichNode,
- WindowPtr pWin);
-
- static void SendDropInWindowRecvNode (
- WindowPtr pWin,
- DragReference theDrag,
- FSSpecPtr pFSSpecList,
- UInt16 numInList);
-
- pascal OSErr HandleAEFileSpecList (
- AppleEvent *pAEvent,
- AppleEvent *pReply,
- SInt32 refCon);
-
- static void HandleDragHilite (
- SInt16 theMessage,
- Rect *iconRect,
- Rect *textRect);
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // External procedure prototypes.
- //
-
- extern OSErr HandleFSItem (
- FSSpecPtr pFSItem,
- FWXNodeID whichNode);
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // Globals
- //
- extern FWXAppDataPtr gpFWXAppData;
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // InstallDragHandlers
- //
- // InstallDragHandlers attaches tracking and receive handlers to our
- // application.
- //
- //
-
- OSErr InstallDragHandlers (void)
- {
- DragTrackingHandlerUPP pDragTracker = nil;
- DragReceiveHandlerUPP pDragReceiver = nil;
- OSErr err = noErr;
-
- gpFWXAppData->dragReceiveHandlerInstalled = false;
- gpFWXAppData->dragTrackingHandlerInstalled = false;
-
- // Create and install the drag tracker
- pDragTracker = NewDragTrackingHandlerProc(HandleDragTracking);
- if (pDragTracker != nil) {
- // We allocated the procpointer, install it.
- err = InstallTrackingHandler(pDragTracker, nil, nil);
-
- if (err == noErr) {
- // We installed the drag tracker.
- gpFWXAppData->dragTrackingHandler = pDragTracker;
- gpFWXAppData->dragTrackingHandlerInstalled = true;
- } else {
- // The drag tracker was allocated but not installed,
- // dispose of the routine descriptor.
- DisposeRoutineDescriptor(pDragTracker);
- return err;
- }
- } else {
- // We could not allocate the proc pointer
- return memFullErr;
- }
-
- // Create and install the drag receiver. If we got this far,
- // the drag tracker is installed.
- pDragReceiver = NewDragReceiveHandlerProc(HandleDragReceive);
- if (pDragReceiver != nil) {
- // We allocated the procpointer, install it.
- err = InstallReceiveHandler(pDragReceiver, nil, nil);
-
- if (err == noErr) {
- // We installed the drag receiver.
- gpFWXAppData->dragReceiveHandler = pDragReceiver;
- gpFWXAppData->dragReceiveHandlerInstalled = true;
- } else {
- // The drag receiver was allocated but not installed,
- // dispose of the routine descriptor, clean up the tracker.
- DisposeRoutineDescriptor(pDragReceiver);
- RemoveTrackingHandler(pDragTracker, nil);
- DisposeRoutineDescriptor(pDragTracker);
- gpFWXAppData->dragTrackingHandlerInstalled = false;
- return err;
- }
- } else {
- // We could not allocate the proc pointer, clean up the tracker.
- RemoveTrackingHandler(pDragTracker, nil);
- DisposeRoutineDescriptor(pDragTracker);
- gpFWXAppData->dragTrackingHandlerInstalled = false;
- return memFullErr;
- }
-
- return err;
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // RemoveDragHandlers
- //
- // Remove the drag handlers from a window prior to closing the window.
- //
-
- void RemoveDragHandlers (void)
- {
- if (gpFWXAppData->dragReceiveHandlerInstalled) {
- RemoveReceiveHandler(gpFWXAppData->dragReceiveHandler , nil);
- DisposeRoutineDescriptor(gpFWXAppData->dragReceiveHandler);
- }
-
- if (gpFWXAppData->dragTrackingHandlerInstalled) {
- RemoveTrackingHandler(gpFWXAppData->dragTrackingHandler, nil);
- DisposeRoutineDescriptor(gpFWXAppData->dragTrackingHandler);
- }
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // MouseInContentRgn
- //
- // returns true if the mouse is in the content area of the window
- // (not necessarily in the visible rgn)
- //
-
- static Boolean MouseIsInContentRgn (
- DragReference theDrag,
- WindowPtr pWin)
- {
- Point mousePt;
-
- GetDragMouse(theDrag, &mousePt, nil);
-
- return PtInRgn(mousePt, ((WindowPeek) pWin)->contRgn);
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // DragItemsAreAcceptable
- //
- // Returns true if the contents (data) of the drag
- // are acceptable. Its a file or folder.
- //
- // Called by the tracking and receive handlers
- //
-
- static Boolean DragItemsAreAcceptable(
- DragReference theDrag)
- {
- OSErr err;
- UInt16 numItems;
- UInt16 indexItem;
- ItemReference itemRef;
- FlavorFlags theFlags;
-
- if (gpFWXAppData->pSenderWindow != FrontWindow())
- return false;
-
- // loop through each item in the drag to make sure it has an HFS flavor
- err = CountDragItems(theDrag, &numItems);
- if (err == noErr) {
- for (indexItem = 1; indexItem <= numItems; indexItem++) {
-
- err = GetDragItemReferenceNumber(theDrag, indexItem, &itemRef);
-
- if (err == noErr) {
- err = GetFlavorFlags(theDrag, itemRef, flavorTypeHFS, &theFlags );
- if (err != noErr)
- return false; // drag item is not hfs, its all or nothing
- } else
- return false; // could not get item reference
- }
- } else {
- return false; // could not count items
- }
-
- return true; // each item is an hfs (should always be that way)
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // HandleDragTracking
- //
- // Called by the drag manager whenever a drag is
- // over one of our windows. On entry the current
- // port has been set to our windows by the Drag Manager.
- //
-
- static pascal OSErr HandleDragTracking (
- DragTrackingMessage theMessage,
- WindowPtr pWin,
- void *handlerRefCon,
- DragReference theDrag)
- {
- //#pragma unused handlerRefCon
- WindowDataPtr pWinData;
- RgnHandle hOldClip;
- Rect iconRect, textRect, drawRect;
- Point localPt;
- SInt16 mouseInWhichSpace;
- SInt16 deltaH, deltaV;
- OSErr err = noErr;
-
- switch (theMessage)
- {
- case kDragTrackingEnterHandler:
- // Initialization for the handler
- (gpFWXAppData->dragHandlerGlobals).acceptableDragFlag =
- DragItemsAreAcceptable(theDrag);
- (gpFWXAppData->dragHandlerGlobals).hilitedSpace = kNoSpace;
- HandleDragHilite(kHiliteInit, &iconRect, &textRect);
-
- // let the drag manager know if we can't accept this drag
- if (!(gpFWXAppData->dragHandlerGlobals).acceptableDragFlag)
- err = dragNotAcceptedErr;
- break;
-
- case kDragTrackingEnterWindow:
- case kDragTrackingInWindow:
- case kDragTrackingLeaveWindow:
- // Handle highlighting the receive node icon
- if (gpFWXAppData->dragHandlerGlobals.acceptableDragFlag)
- {
- pWinData = (WindowDataPtr) GetWRefCon(pWin);
- deltaH = GetControlValue(pWinData->hHScrollBar);
- deltaV = GetControlValue(pWinData->hVScrollBar);
- SetOrigin(deltaH, deltaV);
- GetClip(hOldClip = NewRgn());
- drawRect = pWin->portRect;
- drawRect.bottom -= kScrollBarAdjust;
- drawRect.right -= kScrollBarAdjust;
- ClipRect(&drawRect);
-
- // Unless the mouse is leaving the visible area of the
- // window, check if it's in the window's content region
- if (theMessage == kDragTrackingLeaveWindow)
- mouseInWhichSpace = kNoSpace;
- else
- {
- GetDragMouse(theDrag, &localPt, nil);
- GlobalToLocal(&localPt);
- mouseInWhichSpace = WhichRecvNode(pWin, localPt);
- }
-
- // If the mouse's space is not equal to the hilitedSpace
- // and the mouse is in a space (i.e., a new, different space.)
- if ((mouseInWhichSpace != gpFWXAppData->dragHandlerGlobals.hilitedSpace) &&
- (mouseInWhichSpace != kNoSpace))
- {
- if (gpFWXAppData->dragHandlerGlobals.hilitedSpace != kNoSpace)
- {
- // There is a currently hilited space, unhilite it
- GetNodeDragRect (pWin,
- gpFWXAppData->dragHandlerGlobals.hilitedSpace,
- &iconRect,
- &textRect);
- HandleDragHilite(kHiliteOff, &iconRect, &textRect);
- }
-
- // draw the hilight
- GetNodeDragRect(pWin, mouseInWhichSpace, &iconRect, &textRect);
- HandleDragHilite(kHiliteOn, &iconRect, &textRect);
- gpFWXAppData->dragHandlerGlobals.hilitedSpace = mouseInWhichSpace;
- }
- // else if the mouse is not in the content region
- // and an icon is hilighted, erase the hilight
- else if ((mouseInWhichSpace == kNoSpace) &&
- (gpFWXAppData->dragHandlerGlobals.hilitedSpace != kNoSpace))
- {
- GetNodeDragRect (pWin,
- gpFWXAppData->dragHandlerGlobals.hilitedSpace,
- &iconRect,
- &textRect);
- HandleDragHilite(kHiliteOff, &iconRect, &textRect);
- gpFWXAppData->dragHandlerGlobals.hilitedSpace = kNoSpace;
- }
- SetOrigin(0, 0);
- SetClip(hOldClip);
- DisposeRgn(hOldClip);
- }
- break;
-
- // do nothing for the leaveHandler message
- case kDragTrackingLeaveHandler:
- HandleDragHilite(kHiliteDispose, &iconRect, &textRect);
- break;
-
- // let the drag manager know if we didn't recognize the message
- default:
- err = paramErr;
- }
- return err;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // HandleDragHilite
- //
- // Handle hiliting of node icons in sender window
- static void HandleDragHilite (
- SInt16 theMessage,
- Rect *iconRect,
- Rect *textRect)
- {
- static Handle hIconSuite;
- OSErr err;
-
- switch (theMessage)
- {
- case kHiliteInit:
- err = GetIconSuite(&hIconSuite, kDropIconSuiteID, svAllAvailableData);
- break;
- case kHiliteOff:
- err = PlotIconSuite(iconRect, atNone, ttNone, hIconSuite);
- InvertRect(textRect);
- break;
- case kHiliteOn:
- err = PlotIconSuite(iconRect, atNone, ttSelected, hIconSuite);
- InvertRect(textRect);
- break;
- case kHiliteDispose:
- err = DisposeIconSuite(hIconSuite, false);
- }
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // HandleDragReceive
- //
- // Called by the drag manager when a drag ends in our window
- //
- // Need to loop through each drag item and get its hfs data
- // building a list of fsspec's as we go.
- //
- // Send an AppleEvent to ourselves to handle copying the list.
- //
-
- static pascal OSErr HandleDragReceive (
- WindowPtr pWin,
- void *handlerRefCon,
- DragReference theDrag)
- {
- //#pragma unused handlerRefCon
-
- ItemReference itemRef;
- Size flavorDataSize;
- FSSpecPtr pFSSpecList;
- HFSFlavor itemHFSFlavor;
- UInt16 numItems;
- UInt16 indexItem;
- OSErr err = noErr;
-
- if (! (DragItemsAreAcceptable(theDrag) && MouseIsInContentRgn(theDrag, pWin)))
- return dragNotAcceptedErr;
-
- err = CountDragItems(theDrag, &numItems);
- if (err == noErr)
- {
- // allocate a buffer to grab each of the drag items FSSpecs
- pFSSpecList = (FSSpecPtr) NewPtr(sizeof(FSSpec) * numItems);
- if (pFSSpecList == nil)
- return memFullErr;
-
- for (indexItem = 1; indexItem <= numItems; indexItem++) {
- // reset flavorDataSize through each loop
- // as it gets updated by the GetFlavorData call
- flavorDataSize = sizeof(HFSFlavor);
-
- err = GetDragItemReferenceNumber(theDrag, indexItem, &itemRef);
- if (err != noErr) {
- DisposePtr((Ptr)pFSSpecList);
- return err;
- }
-
- err = GetFlavorData(theDrag, itemRef, flavorTypeHFS,
- &itemHFSFlavor, &flavorDataSize, 0);
- if (err != noErr) {
- DisposePtr((Ptr)pFSSpecList);
- return err;
- }
- pFSSpecList[indexItem-1] = itemHFSFlavor.fileSpec;
- }
- if (err == noErr)
- SendDropInWindowRecvNode(pWin, theDrag, pFSSpecList, numItems);
-
- DisposePtr((Ptr)pFSSpecList);
- }
- return err;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // SendSetterToSelf
- //
- // Send an AppleEvent to ourself with the firewire file exchange
- // receive node ID and the FSSpec list of items to be sent.
- //
-
- OSErr SendFSSpecListToSelf (
- FWXNodeID fwxNodeID,
- FSSpecPtr pFSSpecList,
- UInt16 numFSSpecs)
- {
- AppleEvent send;
- AppleEvent reply;
- AEDesc selfTarget;
- ProcessSerialNumber psn;
- UInt32 longFSSpecCount;
- OSErr err;
-
- longFSSpecCount = numFSSpecs;
- selfTarget.dataHandle = nil;
- send.dataHandle = nil;
-
- GetCurrentProcess(&psn);
- err = AECreateDesc(typeProcessSerialNumber, (Ptr) &psn, sizeof(ProcessSerialNumber), &selfTarget);
- if (err != noErr)
- return err;
-
- err = AECreateAppleEvent(kAEFWXEventClass, kAEFileSpecList, &selfTarget,
- kAutoGenerateReturnID, kAnyTransactionID, &send);
- if (err != noErr) {
- AEDisposeDesc(&selfTarget);
- return err;
- }
-
- err = AEPutParamPtr(&send, kAEFWXNodeIDKey, kAEFWXNodeIDType, (Ptr) &fwxNodeID, sizeof(FWXNodeID));
- if (err != noErr) {
- AEDisposeDesc(&selfTarget);
- if (send.dataHandle != nil)
- AEDisposeDesc(&send);
- return err;
- }
-
- err = AEPutParamPtr(&send, kAEFSSpecKey, typeFSS, (Ptr) pFSSpecList, sizeof(FSSpec)*numFSSpecs);
- if (err != noErr) {
- AEDisposeDesc(&selfTarget);
- if (send.dataHandle != nil)
- AEDisposeDesc(&send);
- return err;
- }
-
- err = AEPutParamPtr(&send, kAEFSSpecCountKey, typeLongInteger, (Ptr) &longFSSpecCount, sizeof(UInt32));
- if (err != noErr) {
- AEDisposeDesc(&selfTarget);
- if (send.dataHandle != nil)
- AEDisposeDesc(&send);
- return err;
- }
-
- err = AESend(&send, &reply, kAENoReply + kAEAlwaysInteract + kAECanSwitchLayer,
- kAENormalPriority, kAEDefaultTimeout, nil, nil);
-
- if (err != noErr) {
- AEDisposeDesc(&selfTarget);
- AEDisposeDesc(&send);
- }
-
- return err;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // GetNodeInfo
- //
- // Return the nodeInfo record for the node id.
- //
-
- OSErr GetNodeInfo (
- FWXNodeID nodeID,
- RecvNodePtr *pRecvNode)
- {
- WindowPtr pWin;
- WindowDataPtr pWinData;
- RecvNodePtr pTempRecvNode;
- SInt16 index;
- OSErr err = noErr;
-
- pWin = gpFWXAppData->pSenderWindow;
- pWinData = (WindowDataPtr) GetWRefCon(pWin);
-
- pTempRecvNode = pWinData->pRecvNodeList;
- for (index = 0; index < pWinData->numRecvNodes; index++) {
- if (pTempRecvNode->nodeID == nodeID)
- break;
- pTempRecvNode = (RecvNodePtr) pTempRecvNode->pNextNode;
- }
-
- *pRecvNode = pTempRecvNode;
- if (pTempRecvNode == nil)
- err = resNotFound; // JKL *** what error?
-
- return err;
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // GetNodeName
- //
- // Get the bounding rectangle of a drag area for the specified index.
- // There is a drag area for each FireWire Exchange node.
- //
-
- OSErr GetNodeName (
- WindowPtr pWin,
- SInt16 nodeIndex,
- StringPtr *pString)
- {
- WindowDataPtr pWinData;
- RecvNodePtr pTempRecvNode;
- SInt16 index;
-
- pWinData = (WindowDataPtr) GetWRefCon(pWin);
- if (nodeIndex > pWinData->numRecvNodes)
- return memFullErr; // JKL - some error
-
- pTempRecvNode = pWinData->pRecvNodeList;
- for (index = 1; index < nodeIndex; index++) {
- pTempRecvNode = (RecvNodePtr) pTempRecvNode->pNextNode;
- }
-
- *pString = pTempRecvNode->nodeName;
-
- return noErr;
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // GetNodeDragRect
- //
- // Get the bounding rectangle of a drag area for the specified index.
- // There is a drag area for each FireWire Exchange node.
- //
-
- OSErr GetNodeDragRect (
- WindowPtr pWin,
- SInt16 nodeIndex,
- Rect *iconRect,
- Rect *textRect)
- {
- WindowDataPtr pWinData;
- RecvNodePtr pTempRecvNode;
- SInt16 index;
-
- pWinData = (WindowDataPtr) GetWRefCon(pWin);
- if (nodeIndex > pWinData->numRecvNodes)
- return memFullErr; // JKL - some error
-
- pTempRecvNode = pWinData->pRecvNodeList;
- for (index = 1; index < nodeIndex; index++) {
- pTempRecvNode = (RecvNodePtr) pTempRecvNode->pNextNode;
- }
-
- *iconRect = pTempRecvNode->recvNodeIconRect;
- *textRect = pTempRecvNode->recvNodeTextRect;
-
- return noErr;
- }
-
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // WhichRecvNode
- //
- // Determine where the drop has taken place. There is a space for each
- // FireWire Exchange node. After doing a compare it will return the space
- // number, or kNoSpace if it didn't land in a space.
- //
-
- SInt16 WhichRecvNode (
- WindowPtr pWin,
- Point localPt)
- {
- WindowDataPtr pWinData;
- RgnHandle iconRgn, textRgn, dragRgn;
- Rect iconRect;
- Rect textRect;
- SInt16 count;
- SInt16 theNodeIndex;
-
- pWinData = (WindowDataPtr) GetWRefCon(pWin);
- theNodeIndex = kNoSpace;
- if (pWinData == nil)
- return theNodeIndex;
-
- iconRgn = NewRgn();
- textRgn = NewRgn();
- dragRgn = NewRgn();
- if (pWinData != nil)
- {
- for (count = 1; count <= pWinData->numRecvNodes; count ++)
- {
- GetNodeDragRect(pWin, count, &iconRect, &textRect);
- RectRgn(iconRgn, &iconRect);
- RectRgn(textRgn, &textRect);
- UnionRgn(iconRgn, textRgn, dragRgn);
- if (PtInRgn(localPt, dragRgn))
- {
- theNodeIndex = count;
- break;
- }
- }
- }
- DisposeRgn(iconRgn);
- DisposeRgn(textRgn);
- DisposeRgn(dragRgn);
- return theNodeIndex;
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // GetNodeIDFromIndex
- //
- // Using an index into the list of receive nodes, get the FireWire File
- // Exchange node id from the indexed node.
- //
-
- static void GetNodeIDFromIndex(
- SInt16 nodeIndex,
- FWXNodeID *whichNode,
- WindowPtr pWin)
- {
- WindowDataPtr pWinData;
- RecvNodePtr pTempRecvNode;
- SInt16 i;
-
- pWinData = (WindowDataPtr) GetWRefCon(pWin);
- *whichNode = (FWXNodeID) kInvalidFWXNodeID;
-
- if (pWinData != nil) {
-
- if (nodeIndex <= pWinData->numRecvNodes) {
- pTempRecvNode = pWinData->pRecvNodeList;
- for (i = 1; i < nodeIndex; i++) {
- pTempRecvNode = (RecvNodePtr) pTempRecvNode->pNextNode;
- }
-
- *whichNode = pTempRecvNode->nodeID;
- }
- }
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // SendDropInWindowRecvNode
- //
- // Get the drag location, convert it to local coordinates. Find which receive
- // node the drop occurred in and send us an AppleEvent with the list of FSSpec's.
- //
-
- static void SendDropInWindowRecvNode (
- WindowPtr pWin,
- DragReference theDrag,
- FSSpecPtr pFSSpecList,
- UInt16 numInList)
- {
- Point thePoint;
- GrafPtr oldPort;
- FWXNodeID whichFWXNode = (FWXNodeID) kInvalidFWXNodeID;
- SInt16 theNodeIndex;
- OSErr err;
-
- GetPort(&oldPort);
- SetPort(pWin);
- GetDragMouse(theDrag, &thePoint, 0L);
- GlobalToLocal(&thePoint);
- theNodeIndex = WhichRecvNode(pWin, thePoint);
- SetPort(oldPort);
-
- if (theNodeIndex != kNoSpace)
- GetNodeIDFromIndex(theNodeIndex, &whichFWXNode, pWin);
-
- if (whichFWXNode != (FWXNodeID) kInvalidFWXNodeID)
- err = SendFSSpecListToSelf(whichFWXNode, pFSSpecList, numInList);
- }
-
- //////////////////////////////////////////////////////////////////////////////
- //
- // HandleAEFileSpecList
- //
- // Pull parameters out of AppleEvent and call routine to handle the drop.
- //
-
- pascal OSErr HandleAEFileSpecList (
- AppleEvent *pAEvent,
- AppleEvent *pReply,
- SInt32 refCon)
- {
- //#pragma unused pReply
- //#pragma unused refCon
-
- OSErr err;
- DescType returnType;
- Size returnSize;
- FWXNodeID whichNode;
- UInt32 numFSSpecs;
- FSSpecPtr pFSSpec;
- UInt16 index;
-
- err = AEGetParamPtr(pAEvent, kAEFWXNodeIDKey, kAEFWXNodeIDType, &returnType,
- (Ptr) &whichNode, sizeof(FWXNodeID), &returnSize);
- if (err != noErr)
- return err;
-
- err = AEGetParamPtr(pAEvent, kAEFSSpecCountKey, typeLongInteger, &returnType,
- (Ptr) &numFSSpecs, sizeof(SInt32), &returnSize);
- if (err != noErr)
- return err;
-
- pFSSpec = (FSSpecPtr) NewPtr(sizeof(FSSpec) * numFSSpecs);
- if (pFSSpec == nil)
- return memFullErr;
-
- err = AEGetParamPtr(pAEvent, kAEFSSpecKey, typeFSS, &returnType,
- (Ptr) pFSSpec, sizeof(FSSpec) * numFSSpecs, &returnSize);
- if (err != noErr)
- return err;
-
- for (index = 0; index < numFSSpecs; index++) {
- err = HandleFSItem(&pFSSpec[index], whichNode);
- if (err != noErr) {
- sprintf(debugStr, "Error in HandleFileList: %d", err);
- FWDebugStr((ConstStr255Param) c2pstr(debugStr));
- break;
- }
- }
-
- DisposePtr((Ptr) pFSSpec);
-
- return err;
- }
-